﻿//Create by daniel @ 2012.8.24
//change log:
//
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using YunCMS.Common;
using System.Web;

namespace YunCMS.Core.Configration
{
    public class SiteConfig : Config
    {
        #region const

        //PATH must be 'const', because it will be call in a constructor (in compile-time not run-time)
        private const string PATH = @"~/Configs/site.config";
        private const string CACHE_KEY = "yuncms_siteconfig";

        private readonly string WATERMARK = @"/siteconfig/watermark";
        private readonly string COPYRIGHT = @"/siteconfig/copyright";
        private readonly string COMPANY = @"/siteconfig/company";
        private readonly string DESCRIPTION = @"/siteconfig/description";
        private readonly string EMAIL = @"/siteconfig/email";
        private readonly string TEL = @"/siteconfig/tel";
        private readonly string KEYWORDS = @"/siteconfig/keywords";

        private readonly string EMAIL_PORT = @"/siteconfig/emailport";
        private readonly string EMAIL_FROM = @"/siteconfig/emailfrom";
        private readonly string EMAIL_ACCOUNT = @"/siteconfig/emailaccount";
        private readonly string EMAIL_NICK = @"/siteconfig/emailnickname";

        private readonly string URL = @"/siteconfig/URL";

        #endregion

        #region constructor


        public SiteConfig()
            : this(PATH)
        {   }

        public SiteConfig(string path)
            : base(path, CACHE_KEY)
        {   }

        #endregion

        #region members

        public Watermark Watermark
        {
            get { return GetWatermarkFromNode(); }
            set { XmlFile.Replace(WATERMARK, ""); }
        }

        public string Copyright
        {
            get { return GetText(COPYRIGHT); }
            set { SetText(COPYRIGHT, value); }
        }

        public string Company
        {
            get { return GetText(COMPANY); }
            set { SetText(COMPANY, value); }
        }

        public string Keywords
        {
            get { return GetText(KEYWORDS); }
            set { SetText(KEYWORDS, value); }
        }

        public string Url
        {
            get { return GetText(URL); }
            set { SetText(URL, value); }
        }

        public string Description
        {
            get { return GetText(DESCRIPTION); }
            set { SetText(DESCRIPTION, value); }
        }

        public string EmailSMTP
        {
            get { return GetText(EMAIL); }
            set { SetText(EMAIL, value); }
        }

        public string EmailPort
        {
            get { return GetText(EMAIL_PORT); }
            set { SetText(EMAIL_PORT, value); }
        }

        public string EmailFrom
        {
            get { return GetText(EMAIL_FROM); }
            set { SetText(EMAIL_FROM, value); }
        }

        public string EmailAccount
        {
            get { return GetText(EMAIL_ACCOUNT); }
            set { SetText(EMAIL_ACCOUNT, value); }
        }
        public string EmailNickName
        {
            get { return GetText(EMAIL_NICK); }
            set { SetText(EMAIL_NICK, value); }
        }

        public string Tel
        {
            get { return GetText(TEL); }
            set { SetText(TEL, value); }
        }

        private readonly string TITLE = @"/siteconfig/TITLE";
        public string Title
        {
            get { return GetText(TITLE); }
            set { SetText(TITLE, value); }
        }

        #endregion

        #region method

        private Watermark GetWatermarkFromNode()
        {
            return new Watermark();
        }       

        #endregion
    }

    public class Watermark
    {
        public string Path { get; set; }
        public int offSetX { get; set; }
        public int offSetY { get; set; }
    }
}
